// 下级城市接口

// 省
ajax({
    url: "http://phpclub.org.cn:8080/api/system/province",
    data: {
        parentId: 1
    },
    success: function (response) {

        console.log(response.data);
        let html = ""
        let provinceList = document.querySelector("#province");
        response.data.forEach(function (item, index) {
            html += `<option id="provinceId" value=${item.id}>${item.name}</option>`
        });
        provinceList.innerHTML += html
        // 市

        document.querySelector("#province").onchange = function (e) {
            let provinceValue = e.target.value
            console.log(provinceValue);
            ajax({
                url: "http://phpclub.org.cn:8080/api/system/province",
                data: {
                    parentId: provinceValue
                },
                success: function (response) {
                    console.log(response.data);
                    let html = ""
                    let cityList = document.querySelector("#city");
                    response.data.forEach(function (item, index) {
                        html += `<option value=${item.id}>${item.name}</option>`
                    });
                    cityList.innerHTML = html
                    // 区县
                    document.querySelector("#city").onchange = function (e) {
                        let cityValue = e.target.value
                        console.log(cityValue);
                        ajax({
                            url: "http://phpclub.org.cn:8080/api/system/province",
                            data: {
                                parentId: cityValue
                            },
                            success: function (response) {
                                console.log(response.data);
                                let html = ""
                                let areaList = document.querySelector("#area");
                                response.data.forEach(function (item, index) {
                                    html += `<option value=${item.id}>${item.name}</option>`
                                });
                                areaList.innerHTML = html
                            }
                        })

                    }
                }
            })

        }

    }

})